//
//  FPIntroViewCell.m
//  FilmParadise
//
//  Created by lanou3g on 15/7/13.
//  Copyright (c) 2015年 DLYgroup. All rights reserved.
//

#import "FPIntroViewCell.h"

@implementation FPIntroViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    CGFloat leftSpace = 20;
   
    CGFloat upSpace = 10;

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectMake(kImageH(leftSpace), kImageH(upSpace), kImageH(100), kImageH(100))];
     //   self.iconImageView.backgroundColor = [UIColor greenColor];
        [self.contentView addSubview:_iconImageView];
        
        //添加播放标记
        self.playImageView = [[UIImageView alloc]initWithFrame:CGRectMake(self.iconImageView.x + self.iconImageView.width - kImageW(50), self.iconImageView.y + self.iconImageView.height - kImageH(50), kImageW(30), kImageW(30))];
        self.playImageView.image = [UIImage imageNamed:@"cm2_rcd_btn_play_prs@3x"];
        [self.iconImageView addSubview:_playImageView];

        self.introLabel = [[UILabel alloc]initWithFrame:CGRectMake(2 * kImageH(leftSpace) + self.iconImageView.frame.size.width, kImageH(upSpace), kImageH(200), kImageH(30))];
      //  self.introLabel.backgroundColor = [UIColor redColor];
        self.introLabel.font = [UIFont systemFontOfSize:15];
        self.introLabel.text = @"喝一碗卖相好的""闺蜜""鸡汤";
        [self.contentView addSubview:_introLabel];
        
        //
        
        
        self.detilIntrolLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.introLabel.frame.origin.x,self.introLabel.frame.origin.y + self.introLabel.frame.size.height + kImageH(10) , kImageH(200), kImageH(30))];
    //  self.detilIntrolLabel.backgroundColor = [UIColor greenColor];
        self.detilIntrolLabel.font = [UIFont systemFontOfSize:13];
        self.detilIntrolLabel.text = @"为何女人愿意为时代姐妹花买单";
        [self.contentView addSubview:_detilIntrolLabel];
        
        //
        self.timeLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.introLabel.frame.origin.x,self.detilIntrolLabel.frame.origin.y + self.detilIntrolLabel.frame.size.height + kImageH(10) , kImageH(80), kImageH(30))];
       // self.timeLabel.backgroundColor = [UIColor redColor];
        self.timeLabel.font = [UIFont systemFontOfSize:11];
        self.timeLabel.text = @"2小时前";
        [self.contentView addSubview:_timeLabel];
        
        self.criticismLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.introLabel.frame.size.width + kImageH(upSpace),self.detilIntrolLabel.frame.origin.y + self.detilIntrolLabel.frame.size.height+ kImageH(10) , kImageH(50), kImageH(30))];
     //  self.criticismLabel.backgroundColor = [UIColor redColor];
        self.criticismLabel.font = [UIFont systemFontOfSize:11];
        self.criticismLabel.text = @"评论 9";
        [self.contentView addSubview:_criticismLabel];
        
        
    }
    return self;
}

//给cell赋值

- (void)cellForModel:(FPIntroModel *)model
{
    if ([model.type integerValue]== 2) {
        self.playImageView.hidden = NO;
    }
    else
    {
        self.playImageView.hidden = YES;
        
    }

    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.image] placeholderImage:nil completed:nil];
    self.introLabel.text = model.title;
    self.detilIntrolLabel.text = model.title2;
    self.criticismLabel.text = [NSString stringWithFormat:@"评论 %ld",model.commentCount];
    NSRange range = {36,2};
    NSString *stringTime = [model.image substringWithRange:range];
    NSUInteger time = [stringTime integerValue];
    if (time > [self setDate]) {
        NSUInteger interval = 12 + time - [self setDate];
        self.timeLabel.text = [NSString stringWithFormat:@"%ld小时前",interval];
    }
    else
    {   NSUInteger interval = [self setDate] - time;
        
         self.timeLabel.text = [NSString stringWithFormat:@"%ld小时前",interval];
    }

}

- (NSUInteger)setDate
{
    NSDate *nowDate = [NSDate date];
    NSCalendar  * cal=[NSCalendar  currentCalendar];
    NSUInteger  unitFlags = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond;
    NSDateComponents * conponent= [cal components:unitFlags fromDate:nowDate];
    NSUInteger hour = [conponent hour];
    return hour;
}
//- (NSString *)setTimeDay:(NSInteger)day Hour:(NSInteger)hour Minute:(NSInteger)minute
//{
//    if (day > 0) {
//        if (hour > 0)
//        {
//            return @"一天前";
//        }
//        else
//        {
//            return [NSString stringWithFormat:@"%ld小时前",hour * -1];
//        }
//    }
//    else
//    {
//        if (hour >= 0) {
//            if (minute > 0 && hour == 0) {
//                return [NSString stringWithFormat:@"%ld分钟前",minute];
//                
//            }
//            else
//            {
//                return [NSString stringWithFormat:@"%ld小时前",hour  ];
//            }
//        }
//        else
//        {
//            NSLog(@"DDDDD%ldHHHHHH%ldMMMMMMM%ld",day,hour,minute);
//            
//            NSLog(@"时间错误!!!!!!!!!!");
//            return nil;
//        }
//    }
//}

@end
